﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Region = Website.Models.Domain.Region
@model Matchmaking
@{
    this.ViewBag.Title = "Matchmaking";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Regions = this.ViewData["Regions"] as List<Region>;
    var Funds = this.ViewData["Funds"] as List<Fund>;
    var PartnerTypes = this.ViewData["PartnerTypes"] as List<MatchmakingPartnerType>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var Profiles = this.ViewData["Profiles"] as List<Profile>;
    var Locations = this.ViewData["Locations"] as List<Location>;
    var MatchMake = Model as Matchmaking;
    var Partner = this.ViewData["Partners"] as MatchmakingPartner;
    var partnerID = Guid.Empty;
    if (Partner != null && Partner.ID != null && Partner.ID != Guid.Empty)
    {
        partnerID = Partner.ID;
    }
    // errorhandling
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }

}

@Html.Partial("~/Views/_Shared/LogView.cshtml", Model.ID)

<script>
    $(function () {
        $("#datepicker").datepicker();
        $('#OwnerProjects').multiSelect();
        $("#Profiles").multiSelect();
    });
</script>

@using (this.Html.BeginForm())
{
    <div class="error">
        @errorMsg
    </div>

    // ********************Matchmaking*********************
    // hidden field to hold ID of the object
    <input type="hidden" id="id" name="id"  readonly="readonly" value="@MatchMake.ID" />
    // hidden field to hold ID of the objects object
    @Html.Hidden("PartnerId", partnerID)

    // name
    <div class="formBullet">Beskrivelse</div>
    <input type="text" id="Name" name="Name" value="@MatchMake.Name"/>

    // date
    <div class="formBullet">Dato</div>
    <input type="text" id="datepicker" name="Date" readonly="readonly" value="@MatchMake.Date" />

    // location
    <div class="formBullet">Lokation</div>
    <div class="formEntry">
        <select name="Location" id="Location">
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in Locations.OrderBy(x => x.Name))
            {

                if (loc.ID == MatchMake.Location)
                {
                <option value="@loc.ID" selected="selected">@loc.Name</option>
                }
                else
                {
                <option value="@loc.ID">@loc.Name</option>
                }
            }
        </select>
    </div>

            // ownerProjects chooser
    <div class="formBullet">Alle projekter tilknyttet</div>
    <div class="formEntry">
        <select multiple="multiple" name="OwnerProjects" id="OwnerProjects">
            @foreach (Project proj in Projects.Where(x => (MatchMake.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@proj.ID" selected="selected">@proj.Name</option>
            }
            @foreach (Project proj in Projects.Where(x => !(MatchMake.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@proj.ID">@proj.Name</option>
            }
        </select>
    </div>
    
            // profiles chooser
    <div class="formBullet">Profiler</div>
    <div class="formEntry">
        <select multiple="multiple" name="Profiles" id="Profiles">
            @foreach (Profile prof in Profiles.Where(x => (MatchMake.Profiles ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@prof.ID" selected="selected">@prof.Name</option>
            }
            @foreach (Profile prof in Profiles.Where(x => !(MatchMake.Profiles ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
    </div>

            // buyers
    <div class="formBullet">Købere</div>
    <input type="text" id="Buyers" name="Buyers" value="@MatchMake.Buyers"/>

            // funds chooser 
    <div class="formBullet">Puljer og fonde</div>
    <div class="formEntry">
        <select multiple="multiple" name="Funds" id="Funds">
            @foreach (Fund fun in Funds.Where(x => (MatchMake.Funds ?? new Guid[0]).Contains(x.ID)))
            {

                <option value="@fun.ID" selected="selected">@fun.Name</option>
            }
            @foreach (Fund fun in Funds.Where(x => !(MatchMake.Funds ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@fun.ID">@fun.Name</option>
            }
        </select>
    </div>

            // funds comments
    <div class="formBullet">Ved "øvrige fonde", hvilken fond?</div>
    <input type="text" id="FundsText" name="FundsText" value="@MatchMake.FundsText" />

            // funds chooser 
    <div class="formBullet">Anden Finansiering</div>
    <div class="formEntry">
        <select multiple="multiple" name="OtherFinancing" id="OtherFinancing">
            @foreach (Fund fun in Funds.Where(x => (x.Type.Equals("Anden finansiering")) && (MatchMake.OtherFinancing ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@fun.ID" selected="selected">@fun.Name</option>
            }
            @foreach (Fund fun in Funds.Where(x => (x.Type.Equals("Anden finansiering")) && !(MatchMake.OtherFinancing ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@fun.ID">@fun.Name</option>
            }
        </select>
    </div>
    <br />
<fieldset class="chosenFields">
    <legend>Samarbejdspartner information</legend>
            @*// Matchmaking Partner*@
    <div class="formBullet">Samarbejdspartner</div>
    <div class="formEntry">
        <select name="Type" id="Type">
            <option value="@Guid.Empty">Vælg en samarbejdspartner</option>

            @foreach (MatchmakingPartnerType pt in PartnerTypes.OrderBy(x => x.Name))
            {
                if (Partner != null)
                {
                    if (pt.ID == Partner.Type)
                    {
                <option value="@pt.ID" selected="selected">@pt.Name</option>
                    }
                    else
                    {
                <option value="@pt.ID">@pt.Name</option>
                    }
                }
                else
                {
                <option value="@pt.ID">@pt.Name</option>
                }
            }
        </select>
    </div>
    



           @* // PD comments*@
    <div class="formBullet">Produkt udvikling</div>
    <textarea id="ProductDevelopmentText" name="ProductDevelopmentText">@if (Partner != null){
                                                @Partner.ProductDevelopmentText
                                            }</textarea>

                                                                        @*// test comments*@
    <div class="formBullet">Test</div>

    <textarea id="TestText" name="TestText">@if (Partner != null){
                                                @Partner.TestText
                                            }</textarea>

                                            @*// sales comments*@
    <div class="formBullet">Salg</div>

    <textarea id="SalesText" name="SalesText">@if (Partner != null){
                                                @Partner.SalesText
                                            }</textarea>


                                              @*// other comments*@
    <div class="formBullet">Andet</div>
    <textarea id="OtherText" name="OtherText">@if (Partner != null){
                                                @Partner.OtherText
                                            }</textarea>
    </fieldset>
            // Other
    <div class="formBullet">Andre kommentarer</div>
    <textarea id="Comments" name="Comments">@MatchMake.Comments</textarea>


    // ********************Submit*********************
    <div class="buttonHolder">
         <script type="text/javascript">
             function confirmDelete() {
                 if (confirm("Er du sikker på at du vil slette aktiviteten? Dette valg kan ikke fortrydes.")) {
                     location.href = '@this.Url.Action("DeleteMatchmaking", new { ID = MatchMake.ID })';
                }
            }
        </script>
            <input type="button" value="Slet" class="deleteButton margin-right-20" 
                 onclick="confirmDelete();"
                />
        <input type="submit" value="Opdatér" />
    </div>
}

<script>

    $(function () {
        $('#Funds').multiSelect();
        $('#OtherFinancing').multiSelect();



    });
</script>
